<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Info extends CI_Controller {

	/**
	 * 渔汛列表
	 */
	public function index(){

		$apiid = isset($_GET["apiid"]) ? intval($_GET["apiid"]) : 0;

		$api = \libraries\waydiao\Wdata::getApi($this->config->item('waydiao'), $apiid);

		$data = [
			'hosts' => $this->config->item('api_host_yuxun'),
			'url' => $api["url"],
			'method' => $api["method"],
			'isAuth' => $api["isAuth"],
		];

		$this->load->view('Info/index', $data);

	}


	public function asyncIndex(){

		$Authorization = isset($_POST["Authorization"]) ? addslashes($_POST["Authorization"]) : "";
		$page = isset($_POST["page"]) ? intval($_POST["page"]) : 1;

		echo $Authorization;

		$data = [
			'page' => $page,
		];

		$header = ["Authorization:Bearer ".$Authorization];

		$r = curl_post_header("http://yuxun.aidiaowu.com:8081/v1/info/index", $data, $header, 8081);

		$r2 = json_decode($r);
		pre($r2);

	}

	/**
	 * 渔汛查看
	 */
	public function view(){

		$apiid = isset($_GET["apiid"]) ? intval($_GET["apiid"]) : 0;

		$api = \libraries\waydiao\Wdata::getApi($this->config->item('waydiao'), $apiid);

		$data = [
			'hosts' => $this->config->item('api_host_yuxun'),
			'url' => $api["url"],
			'method' => $api["method"],
			'isAuth' => $api["isAuth"],
		];

		$this->load->view('Info/view', $data);

	}


	public function asyncView(){

		$Authorization = isset($_POST["Authorization"]) ? addslashes($_POST["Authorization"]) : "";
		$info_id = isset($_POST["info_id"]) ? intval($_POST["info_id"]) : 0;

		echo $Authorization;

		$data = [
			'info_id' => $info_id,
		];

		$header = ["Authorization:Bearer ".$Authorization];

		$r = curl_post_header("http://yuxun.aidiaowu.com:8081/v1/info/view", $data, $header, 8081);

		$r2 = json_decode($r);
		pre($r2);

	}


	/**
	 * 渔汛创建
	 */
	public function create(){

		$apiid = isset($_GET["apiid"]) ? intval($_GET["apiid"]) : 0;

		$api = \libraries\waydiao\Wdata::getApi($this->config->item('waydiao'), $apiid);

		$data = [
			'api' => $api,
			'hosts' => $this->config->item('api_host_yuxun'),
			'url' => $api["url"],
			'method' => $api["method"],
			'isAuth' => $api["isAuth"],
		];

		$this->load->view('Info/create', $data);

	}


	public function asyncCreate(){

		pre($_POST);

		$api_id = isset($_POST["api_id"]) ? intval($_POST["api_id"]) : 0;
		$api_host = isset($_POST["api_host"]) ? addslashes($_POST["api_host"]) : "";
		$Authorization = isset($_POST["Authorization"]) ? addslashes($_POST["Authorization"]) : "";
		$title = isset($_POST["title"]) ? addslashes($_POST["title"]) : "";
		$content = isset($_POST["content"]) ? addslashes($_POST["content"]) : "";
		$activity_id = isset($_POST["activity_id"]) ? addslashes($_POST["activity_id"]) : "";
		$files = isset($_POST["files"]) ? addslashes($_POST["files"]) : "";

		echo $api_id."<br>";
		echo $api_host."<br>";
		echo $Authorization."<br>";
		echo $title."<br>";
		echo $content."<br>";
		echo $activity_id."<br>";
		echo $files."<br>";


		$api = \libraries\waydiao\Wdata::getApi($this->config->item('waydiao'), $api_id);

		$request_url = $api_host.$api["url"];



		echo $request_url."<br>";

		$data = [
			'title' => $title,
			'content' => $content,
			'activity_id' => $activity_id,
			'files' => $files,
		];

		pre($data);

		$header = ["Authorization:Bearer ".$Authorization];

		$r = curl_post_header($request_url, json_encode($data), $header, 8081);

		$r2 = json_decode($r);
		pre($r2);

	}
}
